package bancosys.tec.persist.entities.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Comments;
import jmine.tec.persist.annotation.Index;

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Filters;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.authorization.AuthorizableActionAware;
import bancosys.tec.persist.bussobj.AuthPersistableBusinessObject;

/**
 * @created 11.07.2007
 * @author Gustavo Almeida
 */
@Entity
@Table(name = "FILHO")
@Alias("FILHO")
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "SEQ_FILHO", sequenceName = "SEQ_FILHO", initialValue = 42)
@Filters({ @Filter(name = "authFilter", condition = "auth = :auth") })
@Comments({ @Comment(table = "FILHO", value = "NÃO TINHA COMENTARIOS, BLAH."),
        @Comment(table = "FILHO", column = "ID", value = "NÃO TINHA COMENTARIOS, BLAH.") })
public class Filho extends AuthPersistableBusinessObject implements AuthorizableActionAware {
    private Long id;

    private String name;

    private String authorizationAction;

    public Filho() {
        // OK
    }

    public Filho(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_FILHO")
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public void setPk(Serializable pk) {
        this.id = (Long) pk;
    }

    @Column(name = "NAME", nullable = false)
    @Comment(table = "FILHO", column = "NAME", value = "NÃO TINHA COMENTARIOS, BLAH.")
    @Index(suffix = "0")
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the authAction
     */
    @Column(name = "AUTH_ACTION")
    @Documentation("AUTH ACTION")
    public String getAuthorizationAction() {
        return this.authorizationAction;
    }

    /**
     * @param authAction the authAction to set
     */
    public void setAuthorizationAction(Object authorizationAction) {
        this.authorizationAction = authorizationAction == null ? null : authorizationAction.toString();
    }

    @Override
    public String toString() {
        return "Filho (" + this.getId() + "," + this.getName() + ")";
    }
}
